var mysql = require("mysql");

var pool  = mysql.createPool({
    connectionLimit:10,
    user:"root",
    password:"123456",
    database:"timtest"
})

var query = function(sql,callback) {
    pool.getConnection(function(err,connection){
        if(!err) {
                try {
                     connection.query(sql,function (qerr,rows,fields) {
                        //关闭连接
                        connection.release();
                        //回调
                        callback(qerr,rows,fields);
                     })
                } catch (error) {
                     callback(error,null,null);
                }
        }else{
            callback(err,null,null);
        }
    })
}

module.exports = query;